#ifndef _CRT_COMUTIL_HPP_
#define _CRT_COMUTIL_HPP_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED

#if (TARGET_OS == OS_MACH)
// cocoa/foundation/CFPlugin.h ==> macosx com
#ifndef __COREFOUNDATION_CFPLUGINCOM__
typedef long HRESULT;
#endif
#elif (TARGET_OS == OS_POSIX)
typedef long HRESULT;
#elif (TARGET_OS == OS_UNIX)
typedef long HRESULT;
#endif

#endif

#ifndef S_SUCCESS
#define S_SUCCESS 0
#endif // !S_SUCCESS

#ifndef S_ERROR
#define S_ERROR 1
#endif // !S_ERROR

#ifndef S_FAILD
#define S_FAILD 10
#endif // !S_FAILD

#ifndef S_TIMEOUT
#define S_TIMEOUT 100
#endif // !S_TIMEOUT

#ifndef S_OK
#define S_OK ((HRESULT)0L)
#endif // !S_OK

#ifndef S_FALSE
#define S_FALSE ((HRESULT)1L)
#endif // !S_FALSE

#ifndef S_DELETE
#define S_DELETE ((HRESULT)10L)
#endif // !S_DELETE

#ifndef S_SUCCEEDED
#define S_SUCCEEDED(hr) ((HRESULT)(hr) == S_OK)
#endif

#ifndef S_FAILED
#define S_FAILED(hr) ((HRESULT)(hr) != S_OK)
#endif

#ifndef PURE
#define PURE = 0
#endif

#if (TARGET_OS == OS_WIN)
#define MODULE_API HRESULT OS_STDCALL
#elif (TARGET_OS == OS_POSIX)
#define MODULE_API    HRESULT _VISIBILITY_DEFAULT
#define E_NOTIMPL     1002
#define E_OUTOFMEMORY 1003
#define E_INVALIDARG  1004
#define E_NOINTERFACE 1005
#define E_FAIL        1009
#elif (TARGET_OS == OS_MACH)
#define MODULE_API    HRESULT _VISIBILITY_DEFAULT
#define E_NOTIMPL     1002
#define E_OUTOFMEMORY 1003
#define E_INVALIDARG  1004
#define E_NOINTERFACE 1005
#define E_FAIL        1009
#elif (TARGET_OS == OS_UNIX)
#define MODULE_API    HRESULT _VISIBILITY_DEFAULT
#define E_NOTIMPL     1002
#define E_OUTOFMEMORY 1003
#define E_INVALIDARG  1004
#define E_NOINTERFACE 1005
#define E_FAIL        1009
#endif

#define std_method(method)        virtual HRESULT method
#define std_method_(type, method) virtual type method
#define std_com_export            EXTERN_C MODULE_API

#ifdef __cplusplus
}
#endif

#endif
